import request from "@/utils/request";

import type {
  RequestTrademarkListParamsType,
  RequestTrademarkListReturnType,
  RequestAddTardemarkParamsType,
  RequestUpdataTardemarkParamsType,
  RequestCartgoryOneReturnType,
  RequestCartgoryTwoReturnType,
  RequestCartgoryThreeReturnType,
  RequestTardemarkAttrListParamsType,
  RequestTardemarkAttrListReturnType,
  RequestTardemarkAttrListReturnItemType,
  SpuBaseSaleAttrListType,
  SpuInfoType,
  SpuInfoListType,
  SkuListType,
  SkuItemType,
  SkuListPageType,
  SpuSaleAttrListType,
  TardemarkListType,
  SpuImageListType,
} from "./interface";

// TODO: 品牌列表

// 请求品牌列表数据
export const requestTardemarkList = ({
  page,
  limit,
}: RequestTrademarkListParamsType) => {
  return request.get<any, RequestTrademarkListReturnType>(
    `/admin/product/baseTrademark/${page}/${limit}`
  );
};

// 新增品牌数据
export const requestAddTardemark = (
  TardemarkData: RequestAddTardemarkParamsType
) => {
  return request.post<any, null>(
    "/admin/product/baseTrademark/save",
    TardemarkData
  );
};

// 修改品牌数据
export const requestUpdateTardemark = (
  TardemarkData: RequestUpdataTardemarkParamsType
) => {
  return request.put<any, null>(
    `/admin/product/baseTrademark/update`,
    TardemarkData
  );
};

// 删除品牌数据
export const requestDeleteTardemark = (id: number) => {
  return request.delete<any, null>(`/admin/product/baseTrademark/remove/${id}`);
};

//获取所有的品牌列表
export const requestAllTmList = () => {
  return request.get<any, TardemarkListType>(
    `/admin/product/baseTrademark/getTrademarkList`
  );
};

// TODO: 属性管理

// 一级分类数据
export const requestCartgoryOne = () => {
  return request.get<any, RequestCartgoryOneReturnType>(
    "/admin/product/getCategory1"
  );
};

// 二级分类数据
export const requestCartgoryTwo = (category1Id: number) => {
  return request.get<any, RequestCartgoryTwoReturnType>(
    `/admin/product/getCategory2/${category1Id}`
  );
};

// 三级分类数据
export const requestCartgoryThree = (category2Id: number) => {
  return request.get<any, RequestCartgoryThreeReturnType>(
    `/admin/product/getCategory3/${category2Id}`
  );
};

// 请求品牌属性列表数据
export const requestTardemarkAttrList = ({
  category1Id,
  category2Id,
  category3Id,
}: RequestTardemarkAttrListParamsType) => {
  return request.get<any, RequestTardemarkAttrListReturnType>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
  );
};

// 新增&修改品牌属性数据
export const requestAddOrUpdateTardemarkAttr = (
  tardemarkAttr: RequestTardemarkAttrListReturnItemType
) => {
  return request.post<any, null>("/admin/product/saveAttrInfo", tardemarkAttr);
};

// 删除品牌属性数据
export const requestDeleteTardemarkAttr = (attrId: number) => {
  return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
};

// TODO: Spu 管理

// 请求 Spu 基础销售属性列表
export const requestBaseSaleAttrList = () => {
  return request.get<any, SpuBaseSaleAttrListType>(
    "/admin/product/baseSaleAttrList"
  );
};

// 根据 SpuId 删除 Spu
export const requestDeleteSpuBySupId = (spuId: number) => {
  return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`);
};

// 新增 Spu
export const requestAddSpu = (spuInfo: SpuInfoType) => {
  return request.post<any, null>("/admin/product/saveSpuInfo", spuInfo);
};

// 修改 Spu
export const requestUpdateSpu = (spuInfo: SpuInfoType) => {
  return request.post<any, null>("/admin/product/updateSpuInfo", spuInfo);
};

// 获取 Spu 分页列表
export const requestSpuList = (
  page: number,
  limit: number,
  category3Id: number
) => {
  return request.get<any, SpuInfoListType>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  );
};

// TODO: Sku 管理

// 下架 Sku
export const requestCancelSale = (skuId: number) => {
  return request.get<any, null>(`/admin/product/cancelSale/${skuId}`);
};

// 上架 Sku
export const requestOnSale = (skuId: number) => {
  return request.get<any, null>(`/admin/product/onSale/${skuId}`);
};

// 删除 Sku
export const requestDeleteSale = (skuId: number) => {
  return request.delete<any, null>(`/admin/product/deleteSku/${skuId}`);
};

// 获取 Sku 列表(根据 spuId)
export const requestSkuListById = (spuId: number) => {
  return request.get<any, SkuListType>(`/admin/product/findBySpuId/${spuId}`);
};

// 获取单个 sku 的详细信息
export const requestSkuItem = (skuId: number) => {
  return request.get<any, SkuItemType>(`/admin/product/getSkuById/${skuId}`);
};

// 获取 Sku 列表(分页)
export const requestSkuList = (page: number, limit: number) => {
  return request.get<any, SkuListPageType>(
    `/admin/product/list/${page}/${limit}`
  );
};

// 新增 Sku
export const requestAddSku = (sku: SkuItemType) => {
  return request.post<any, null>("/admin/product/saveSkuInfo", sku);
};

// 获取 Spu 对应的所有的 Sku 的销售属性
export const requestSpuSaleAttrListById = (spuId: number) => {
  return request.get<any, SpuSaleAttrListType>(
    `/admin/product/spuSaleAttrList/${spuId}`
  );
};

// 获取 Spu 对应的所有的 Sku 的图片属性
export const requestSpuImageListById = (spuId: number) => {
  return request.get<any, SpuImageListType>(
    `/admin/product/spuImageList/${spuId}`
  );
};
